Enter age ? 23 adult rate done
In detail what happens is:
IF
is tested: AGE <= 16END IF
: "done" is printed.In the new version of the program, the test is different from the test in the first version of the program, so the true branch and false branch of the program had to be rearranged.
The tests in IF
statements (and DO WHILE statements) need to be looked at
in detail:
A relational expression compares two numbers and results in "true" or "false".
You have been using relational expressions in the condition part
of IF
and DO WHILE statements.
A Relational Symbol says what comparison you want to make
(sometimes relational symbols are called relational operators.)
Here is the list of relational symbols, repeated from chapter 9:
Symbol | Example | Meaning |
---|---|---|
= | A = B | is A equal to B ? |
< | A < B | is A less than B ? |
<= | A <= B | is A less than or equal to B ? |
> | A > B | is A Greater than B ? |
>= | A >= B | is A Greater than or equal to B ? |
<> | A <> B | is A different than B ? |
As a review, fill in the blanks in the following chart:
comparison | true | false |
---|---|---|
-7 = 17 | ||
17 > -1 | ||
17 <= -1 | ||
2 < 4 | ||
2 >= 2 | ||
17 <> 17 |